package com.bjgzy.courselive.di.module;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.bjgzy.courselive.mvp.contract.CoursePlayContract;
import com.bjgzy.courselive.mvp.model.CoursePlayModel;
import com.bjgzy.module_couselive.R;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonres.utils.RxUtil;
import com.eduhzy.ttw.commonsdk.entity.CourseCommentData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.commonsdk.http.CommonApi;
import com.jess.arms.di.scope.ActivityScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-8-2 9:06:52
 */
@Module
public class CoursePlayModule {
    private CoursePlayContract.View view;

    public CoursePlayModule(CoursePlayContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    CoursePlayContract.View provideCoursePlayView() {
        return this.view;
    }
    @ActivityScope
    @Provides
    CoursePlayContract.Model provideCoursePlayModel(CoursePlayModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    List<CourseCommentData> provideLists() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    BaseQuickAdapter<CourseCommentData, AutoBaseViewHolder> provideAdapter(List<CourseCommentData> lists) {
        return new BaseQuickAdapter<CourseCommentData, AutoBaseViewHolder>(R.layout.courselive_rv_item_comment, lists) {
            @Override
            protected void convert(AutoBaseViewHolder helper, CourseCommentData item) {
                Glide.with(helper.itemView.getContext())
                        .load(CommonApi.APP_AVATAR + item.getUserId())
                        .apply(RequestOptions.placeholderOf(R.drawable.img_touxiang).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_avatar));
                helper.setText(R.id.tv_name, item.getRealName());
                helper.setText(R.id.tv_content, RxUtil.fromHtml(item.getContent()));
            }
        };
    }

    @ActivityScope
    @Provides
    RecyclerView.LayoutManager provideLayoutmanager() {
        return new LinearLayoutManager(view.getActivity());
    }
}